<template>
  <div>
    <div class="title">热销产品</div>
    <ul v-if="showRecommend">
        <router-link tag="li" class="item border-bottom" v-for="item of recommendList" :key="item.id" :to="'/detail/' + item.id">
          <div class="item-img-wapper">
            <img class="item-img" :src="item.imgUrl" />
          </div>
          <div class="item-info">
            <p class="item-title">{{item.title}}</p>
            <p class="item-desc">{{item.desc}}</p>
            <button class="item-button">查看详情</button>
          </div>
        </router-link>
    </ul>
  </div>
</template>

<script type="text/javascript">
export default {
  name: 'HomeRecommend',
  props: {
    recommendList: Array
  },
  computed: {
    showRecommend () {
      return this.recommendList.length
    }
  }
}
</script>

<style type="text/javastyle" lang="stylus" scoped>
@import '~styles/mixins.styl'
.title
  line-height: .6rem //这样设置文字自动垂直居中
  text-indent: .2rem
  background: #eee
.item
  overflow: hidden
  display: flex
  height: 1.9rem
  .item-img
    width: 1.7rem
    padding: .1rem
  .item-info
    flex: 1
    min-width: 0
    .item-title
      line-height: .54rem
      font-size: .32rem
      ellipsis()
    .item-desc
      line-height: .4rem
      color: #aaa
      ellipsis()
    .item-button
      margin-top: .2rem
      background: #ff9300
      color: #fff
      padding: .1rem .2rem
      border-radius: .06rem
</style>
